package apiday02;

public class RegDemo09 {
    public static void main(String[] args) {
        /*
         *测试：匹配Hello World，中间至少有一个空白
         */
        String reg = "Hello\\s+World";//   \s+:表示至少有一个空白符
        String s1 = "HelloWorld";
        String s2 = "Hello World";
        String s3 = "Hello  World";
        String s4 = "Hello   World";
        System.out.println(s1.matches(reg));
        System.out.println(s2.matches(reg));
        System.out.println(s3.matches(reg));
        System.out.println(s4.matches(reg));
        System.out.println("-----------");

        String reg1 = "Hello\\s?World";//   \s？:最多有一个空白符
        System.out.println(s1.matches(reg1));
        System.out.println(s2.matches(reg1));
        System.out.println(s3.matches(reg1));
        System.out.println(s4.matches(reg1));
        System.out.println("-----------");

        String reg2 = "Hello\\s*World";//   \s+:表示至少有0个空白符
        System.out.println(s1.matches(reg2));
        System.out.println(s2.matches(reg2));
        System.out.println(s3.matches(reg2));
        System.out.println(s4.matches(reg2));
    }
}
